package com.wt.admin.domain.entity.ai;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.wt.admin.config.JacksonTypeHandler;
import com.wt.admin.domain.entity.PublicEntity;
import lombok.Data;
import org.springframework.ai.chat.messages.*;

import java.util.List;

@Data
@TableName(value = "ai_chat_content", autoResultMap = true)
public class ChatModelContentEntity extends PublicEntity {

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @TableField(value = "agents_id")
    private Integer agentsId;

    @TableField(value = "user_id")
    private Integer userId;

    @TableField(value = "name")
    private String name;

    @TableField(value = "content",typeHandler = JacksonTypeHandler.class)
    private List<Object> content;


    @Data
    public static class Contents {
        public String role;
        public String content;


        public Message toMessage(){
            return switch (role){
                case "user" -> {
                    Contents bean = BeanUtil.toBean(this, Contents.class);
                    yield new UserMessage(bean.content);
                }
                case "system" -> {
                    Contents bean = BeanUtil.toBean(this, Contents.class);
                    yield new SystemMessage(bean.content);
                }
                default -> null;
            };
        }
    }

}
